package com.dy.scs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.dy.scs.mapper.StudentMapper;
import com.dy.scs.pojo.Student;
import com.dy.scs.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public Page<Student> pages(Integer pages, Integer pageSize,String key,String sortBy,String sortType) {
        Page<Student> page = new Page<>(pages, pageSize);
        QueryWrapper<Student> queryWrapper=new QueryWrapper<>();
        if(sortBy!=null&&!sortBy.isEmpty()){
            if("asc".equalsIgnoreCase(sortType))
                queryWrapper.orderByAsc(sortBy);
            if("desc".equalsIgnoreCase(sortType))
                queryWrapper.orderByDesc(sortBy);
        }
        if(key!=null&&!key.isEmpty()){
            queryWrapper.like("sname",key)
                    .or().like("sno",key)
                    .or().like("sage",key)
                    .or().like("ssex",key)
                    .or().like("sdept",key);
        }
        return page(page, queryWrapper);
    }
}
